package com.csun.cmny.provider.service.impl;

import com.csun.cmny.provider.model.domain.MqMessageData;
import com.csun.cmny.provider.model.dto.SendMessageRequest;
import com.csun.cmny.provider.service.OpcManager;
import com.csun.cmny.provider.service.OpcMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-11-07 13:23
 * @Description:
 */
@Slf4j
@Service
public class OpcMessageServiceImpl implements OpcMessageService {

    @Resource
    private OpcManager opcManager;
    @Resource
    private OpcPushMessageProducer messageProducer;

    /**
     * push by user
     *
     * @param sendMessageRequest
     */
    @Override
    public void pushByUser(SendMessageRequest sendMessageRequest) {

        MqMessageData mqMessageData = getMessage(sendMessageRequest);

        opcManager.sendMessage(mqMessageData);
    }

    /**
     * push with msg code
     *
     * @param sendMessageRequest
     */
    @Override
    public void pushWithMsgCode(SendMessageRequest sendMessageRequest) {

        MqMessageData mqMessageData = getMessage(sendMessageRequest);

        opcManager.sendMessage(mqMessageData);
    }

    private MqMessageData getMessage(SendMessageRequest sendMessageRequest) {

        return messageProducer.sendMessageMq(sendMessageRequest);
    }
}
